package com.liang.blog.security.config;

import com.liang.blog.security.interceptor.HeaderInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置
 *
 * @Author：YanWenLiang
 * @Date:2023-08-23-22:15
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private HeaderInterceptor headerInterceptor;

    /** 不需要拦截地址 */
    public static final String[] excludeUrls = { "/verifyCode/*","/login","/register", "/logout",
            "/user/getLoginUserInfo/*", "/sendLoginEmail/**", "/emailLogin",
            "/user/setLoginIp/**", "/user/getUserCount/**", "/user/saveUser","/user/getUserById/**",
            "/refresh", "/dict/**", "/article/public/**", "/sendRegisterEmail/**",
            "/user/public/**"};

    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        registry.addInterceptor(headerInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludeUrls)
                .order(-10);
    }

//    /**
//     * 自定义请求头拦截器
//     */
//    public HeaderInterceptor getHeaderInterceptor(@Qualifier HeaderInterceptor headerInterceptor)
//    {
//        return headerInterceptor;
//    }
}
